<template>
  <div class="app-container">
    <el-form :model="ruleForm" style="width: 40%;margin: 30px auto 0" label-width="100px" @submit.native.prevent>
      <el-form-item label="搜索条件：" prop="username">
        <el-input style="width: 50%" v-model="ruleForm.search_key" clearable placeholder="请输入账户/手机号/id/商户号"></el-input>
        <el-button native-type="submit" type="primary" class="loginNew-login" @click="Query">搜索</el-button>
      </el-form-item>
      <p v-if="form.user_data_exist===false||form.user_data_exist===null">
        京东未注册
      </p>
      <div v-else>
        <el-button type="primary" class="loginNew-login"
                   v-if="form.have_new_channel_apply===false"
                   @click="startSddTempData">申请开通渠道
        </el-button>
        <el-button type="primary" class="loginNew-login"
                   v-else-if="form.is_handle===false"
                   @click="entersingleByUser">商户入驻
        </el-button>
        <el-button type="primary" class="loginNew-login"
                   v-else-if="form.change_channel===true&&form.user_channel_model.switch_state===0"
                   @click="changeData">切换新渠道
        </el-button>
      </div>
    </el-form>
  </div>
</template>

<script>
export default {
  data: function () {
    return {
      ruleForm: {
        search_key: '',
      },
      form: {
        user_data_exist: '',
        have_new_channel_apply: '',
        is_handle: '',
        change_channel: '',
        user_channel_model: {}
      },
    }
  },
  methods: {
    //注册新用户
    Query() {
      this.$get(this.$rkapi + '/minipropram/jd/get_user_jd_channel', {
        "search_key": this.ruleForm.search_key,
      }, true)
          .then((data) => {
            if (data.code === 0) {
              this.form = data.data
            } else {
              this.$notify({
                title: '提示',
                message: data.msg,
                type: 'error'
              })
            }
          })
    },
    startSddTempData() {
      this.$get(this.$rkapi + '/minipropram/jd/start_add_temp_data', {
        "baseuserid": this.form.user_channel_model.bid,
      }, true)
          .then((data) => {
            if (data.code === 0) {
              this.$notify({
                title: '提示',
                message: data.msg,
                type: 'success'
              })
            } else {
              this.$notify({
                title: '提示',
                message: data.msg,
                type: 'error'
              })
            }
          })
    },
    entersingleByUser() {
      this.$get(this.$rkapi + '/minipropram/jd/entersingle_by_user', {
        "baseuserid": this.form.user_channel_model.bid,
      }, true)
          .then((data) => {
            if (data.code === 0) {
              this.$notify({
                title: '提示',
                message: data.msg,
                type: 'success'
              })
            } else {
              this.$notify({
                title: '提示',
                message: data.msg,
                type: 'error'
              })
            }
          })
    },
    changeData() {
      this.$get(this.$rkapi + '/minipropram/jd/change_data', {
        "baseuserid": this.form.user_channel_model.bid,
      }, true)
          .then((data) => {
            if (data.code === 0) {
              this.$notify({
                title: '提示',
                message: data.msg,
                type: 'success'
              })
            } else {
              this.$notify({
                title: '提示',
                message: data.msg,
                type: 'error'
              })
            }
          })
    },
  }
}
</script>
